<!--
* description: 总部审核
* author: wangjuan
* createdDate:2020-12-19
-->
<template>
  <section class="editHQAudit">
    <el-dialog
      v-dialogDrag
      :title="titleName"
      :visible="isDialogVisible"
      :append-to-body="true"
      width="70%"
      :close-on-click-modal="false"
      @close="closeEdit"
    >
      <p class="prompt">注：合同为PDF格式、其他资料为JPG格式（以扫描件形式上传）、身份证正反面在同一页</p>
      <dialogHeader
        slot="title"
        :title="titleName"
        :style-type="$store.state.app.dialogType"
      />

      <div class="filter-container filter-title">车辆信息</div>
      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents1.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="true"
            :is-require="comp.isRequire"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :o-fields="comp.oFields"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>

      <div class="filter-container filter-title">发票信息</div>
      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents2.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="true"
            :is-require="comp.isRequire"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :o-fields="comp.oFields"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>

      <div class="filter-container filter-title">行驶证信息</div>
      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents3.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="true"
            :is-require="comp.isRequire"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :o-fields="comp.oFields"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>

      <div class="filter-container filter-title">开票人信息（企业）</div>
      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents4.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="true"
            :is-require="comp.isRequire"
            :span="comp.span || 8"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :o-fields="comp.oFields"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>

      <div class="filter-container filter-title">操作记录</div>
      <div class="app-container app-container-table">
        <one-table-template
          ref="multipleTable"
          :dynamic-components="tableComponents"
          :dynamic-table-cols="tableCols"
          :dynamic-api-config="apiConfig"
          :dynamic-form-fields="formField"
          :dynamic-is-show-select="false"
          :dynamic-is-show-more-btn="true"
          :dynamic-is-init-table="true"
          :dynamic-table-defult-height="350"
        />
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          :icon="comp.icon"
          :fixed="true"
          @click="comp.clickEvent"
        >{{ comp.text }}</el-button>
      </div>

      <inEdit
        :data-for-form="formField"
        :popups-visible.sync="inEditPopupsVisible"
        :popups-state="inEditPopupsState"
        @closeInEdit="closeInEdit"
        @queryTableon="queryTableon"
      />
    </el-dialog>
  </section>
</template>

<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import { formMixins } from '@/components/mixins/formMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import api from '@/api/subsidyManage'
import inEdit from './inEdit.vue'

export default {
  components: {
    OneTableTemplate,
    inEdit,
    dialogHeader: () => import('@/components/dialogHeader')
  },

  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins, formMixins],
  props: {
    dataForForm: {
      type: Object,
      default: () => {}
    },
    titleName: {
      type: String,
      default: ''
    },
    isDialogVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    const viewPageCode = 'HQAudit-edit'
    return {
      inEditPopupsState: '',
      inEditRowData: {},
      inEditPopupsVisible: false,
      apiConfig: api.findHqSubsidyById,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          name: 'examine',
          icon: 'iconfont icon-examine',
          clickEvent: () => this.inEdit(),
          text: '审核通过',
          position: 'right'
        },
        {
          compKey: 'btnKey2',
          size: 'small',
          name: 'reject',
          icon: 'iconfont icon-reject',
          clickEvent: () => this.reject(),
          text: '驳回'
        }
      ],

      // 动态组件-查询条件
      tableComponents1:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '合格证编号：',
              codeField: 'qualifiedCertNo',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '车辆制造日期：',
              codeField: 'produceDate',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '车型名称：',
              codeField: 'carConfigCn',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: '补贴上牌省份：',
              codeField: 'provinceName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: '补贴上牌城市：',
              codeField: 'cityName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            }
          ],

      // 动态组件-查询条件
      tableComponents2:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey6',
              labelName: '发票号码：',
              codeField: 'invoiceNo',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey7',
              labelName: '开票日期：',
              codeField: 'invoiceDate',
              component: () => import('@/components/org/datePicker/datePicker'),
              type: 'datePicker',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey8',
              labelName: 'VIN码：',
              codeField: 'vin',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey9',
              labelName: '开票价格：',
              codeField: 'invoicePrice',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey10',
              labelName: '销货单位名称：',
              codeField: 'dlrFullNameC',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey11',
              labelName: '发票扫描件：',
              codeField: 'invoiceFile',
              component: () => import('@/components/ve/imageUpload/imgView'),
              isRequire: true,
              isMust: true,
              span: 24
            }
          ],

      // 动态组件-查询条件
      tableComponents3:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey12',
              labelName: '行驶证注册日期：',
              codeField: 'licenseDate',
              component: () => import('@/components/org/datePicker/datePicker'),
              type: 'datePicker',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey13',
              labelName: '车牌号：',
              codeField: 'carLicenseNo',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey14',
              labelName: '行驶证所有人：',
              codeField: 'licenseBelong',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey15',
              labelName: 'VIN码：',
              codeField: 'vin',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey16',
              labelName: '品牌型号：',
              codeField: 'bandCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey17',
              labelName: '使用性质：',
              codeField: 'useNature',
              component: () => import('@/components/org/LookupValue'),
              oField: 'useNatureId,useNatureText',
              options: [
                { useNatureId: '1', useNatureText: '营运' },
                { useNatureId: '2', useNatureText: '非营运' }
              ],
              type: 'dropdownList',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey18',
              labelName: '行驶证扫描件：',
              codeField: 'drlFile',
              component: () => import('@/components/ve/imageUpload/imgView'),
              type: 'inputText',
              isRequire: true,
              isMust: true,
              span: 24
            }
          ],

      // 动态组件-查询条件
      tableComponents4:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey19',
              labelName: '企业名称：',
              codeField: 'enterpriseName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey20',
              labelName: '统一社会信用代号',
              codeField: 'socialCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey21',
              labelName: '企业联系电话：',
              codeField: 'enterprisePhone',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey22',
              labelName: '企业地址：',
              codeField: 'enterpriseAdd',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true,
              span: 24
            },
            {
              compKey: 'compKey23',
              labelName: '营业执照扫描件：',
              codeField: 'enterpriseFile',
              component: () => import('@/components/ve/imageUpload/imgView'),
              type: 'inputText',
              isRequire: true,
              isMust: true,
              span: 24
            },
            {
              compKey: 'compKey24',
              labelName: '法人姓名：',
              codeField: 'corpName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isRequire: true,
              isMust: true
            },
            {
              compKey: 'compKey25',
              labelName: '法人身份证号：',
              codeField: 'corpCredNo',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey26',
              labelName: '法人联系电话：',
              codeField: 'corpRepPhone',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey27',
              labelName: '法人地址：',
              codeField: 'corpAddress',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              span: 24
            },
            {
              compKey: 'compKey28',
              labelName: '法人身份证扫描件：',
              codeField: 'corpFile',
              component: () => import('@/components/ve/imageUpload/imgView'),
              type: 'inputText',
              isRequire: true,
              isMust: true,
              span: 24
            }
          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'subsidyId',
              label: '主键ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'logType',
              label: '操作类型'
            },
            {
              prop: 'logContent',
              label: '操作说明'
            },
            {
              prop: 'logMan',
              label: '操作人'
            },
            {
              prop: 'logTime',
              label: '操作时间'
            }
          ],

      // 标题
      textMap: {
        edit: '总部审核'
      },

      // 表单数据（无需赋值，由混入对象赋值）
      formField: this.$utils.getFormField(this, {

      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },
  created() {
    this.formField = this.dataForForm
  },

  methods: {
    // 关闭弹窗
    closeEdit() {
      this.$emit('close')
    },
    // 审核通过
    inEdit() {
      // this.inEditPopupsState = '审核通过'
      // this.inEditPopupsVisible = true
      this.$requestAPI({
        apiUrl: api.allauditSubsidy.APIUrl,
        variables: { updateControlId: this.dataForForm.updateControlId, subsidyId: this.dataForForm.subsidyId, logContent: '' }
      }).then(res => {
        this.$message(res.msg)
        if (res.result === '1') {
          this.$emit('close')
        }
      })
    },
    // 审核驳回
    reject() {
      this.inEditPopupsState = '审核驳回'
      this.inEditPopupsVisible = true
    },
    // 关闭审核/驳回弹窗
    closeInEdit() {
      this.inEditPopupsVisible = false
      this.closeEdit()
    },
    queryTableon() {
      this.$emit('close')
      this.inEditPopupsVisible = false
    }
  }

}
</script>

<style lang="scss" scoped>
  .filter-title{
    font-size: 18px;
    font-weight: bolder;
  }
  .filter-container.filter-title::before{
    border-left: 4px solid #0075FF;
    padding-right: 10px;
    height: 20px;
    left: 0px;
    top: 4px;
  }
  .prompt{
    color: #e70020;
    width: 100%;
    height: 45px;
    position: absolute;
    left: 15px;
    top: 25px;
    margin-top: 10px;
  }
  /deep/.el-dialog__body{
    margin-top: 30px;
    height: 500px;
  }
  /deep/.filter-params .el-col {
    margin-bottom: 15px;
  }
</style>
